﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.User;
using CE.PostCode;
using CE.CarInsurance;
using CE.Provider;
using CE.Security;
using CE.InputOut;
using CE.Payment;
using CXDecryption;

public partial class car_Insurance_new_proposalforms_bki_proposal_form : MyLanguageBasePage
{
    public static Int64 _CarId, _CarMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;
    public static DateTime _dtDOB1 = General.GetUTCDateTime();
    public static DateTime _dtDOB2 = General.GetUTCDateTime();
    public static DateTime _dtDOB3 = General.GetUTCDateTime();
    public static DateTime _dtDOB4 = General.GetUTCDateTime();
    public static DateTime _dtDOB5 = General.GetUTCDateTime();
    string _redirectUrl = "";
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        //UICulture = selectedCulture;
        Culture = selectedCulture;
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.ProposalTitle;
        
        if (Session[General.CarId] == null || Session[General.CarPolicyId] == null)
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/default.aspx", Page);
            Response.Redirect(_redirectUrl);
        }
        else
        {
            if (!CheckConfirmStatus())
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
        }
        if (Session[CE.Global.General.CarResultId] != null)
        {
            if (Session[General.ProviderCompanyId].ToString() != "32")
            {
                if (Session[CE.Global.General.UserId] != null)
                {
                    _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                    Response.Redirect(_redirectUrl);
                }
                else
                {
                }
            }
        }
        else
        {
            if (Session[CE.Global.General.UserId] != null)
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/default.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
        }

        /* *For Desing Update */
        if (!IsPostBack)
        {
            Session["CIMSG"] = null;
            Session["UMMSG"] = null;

            #region Set Property
            if (Session[CE.Global.General.UserPhoneNo] != null)
            {
                txtContactNo.PhoneNo = Session[CE.Global.General.UserPhoneNo].ToString();
            }
            if (Session[CE.Global.General.UserName] != null)
            {
                txtName.Text = Session[CE.Global.General.UserName].ToString();
            }
            LoadCarPolicyDetails();
            LoadCardExpiryMonth();
            LoadCardExpiryYear();
            #endregion

            #region Validation Effect

            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "')");
            txtIdentificationNo.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtIdentificationNo.ClientID + "','" + rfvIdentificationNo.ClientID + "','" + revIdentificationNo.ClientID + "')");
            txtDriverSurName1.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName1.ClientID + "','" + rfvDriverSurName1.ClientID + "')");
            txtDriverSurName2.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName2.ClientID + "','" + rfvDriverSurName2.ClientID + "')");
            txtDriverSurName3.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName3.ClientID + "','" + rfvDriverSurName3.ClientID + "')");
            txtDriverSurName4.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName4.ClientID + "','" + rfvDriverSurName4.ClientID + "')");
            txtDriverSurName5.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName5.ClientID + "','" + rfvDriverSurName5.ClientID + "')");

            txtBeneficiaryName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtBeneficiaryName.ClientID + "','" + rfvBeneficiaryName.ClientID + "','" + revBeneficiaryName.ClientID + "')");
            txtCarPlate.Attributes.Add("onblur", "ShowValidationEffect('" + txtCarPlate.ClientID + "','" + rfvCarPlate.ClientID + "')");
            txtCarPlateProvince.Attributes.Add("onblur", "ShowValidationEffect('" + txtCarPlateProvince.ClientID + "','" + rfvCarPlateProvince.ClientID + "')");
            txtPresentAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtPresentAddress.ClientID + "','" + rfvPresentAddress.ClientID + "')");
            txtSubDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + txtSubDistrict.ClientID + "','" + rfvSubDistrict.ClientID + "')");
            txtDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + txtDistrict.ClientID + "','" + rfvDistrict.ClientID + "')");
            txtProvince.Attributes.Add("onblur", "ShowValidationEffect('" + txtProvince.ClientID + "','" + rfvProvince.ClientID + "')");
            txtPostalCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostalCode.ClientID + "','" + rfvPostalCode.ClientID + "','" + revPostalCode.ClientID + "')");

            txtMailingAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtMailingAddress.ClientID + "','" + rfvMailingAddress.ClientID + "')");
            txtMailingSubDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + txtMailingSubDistrict.ClientID + "','" + rfvMailingSubDistrict.ClientID + "')");
            txtMailingDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + txtMailingDistrict.ClientID + "','" + rfvMailingDistrict.ClientID + "')");
            txtMailingProvince.Attributes.Add("onblur", "ShowValidationEffect('" + txtMailingProvince.ClientID + "','" + rfvMailingProvince.ClientID + "')");
            txtMailingPostalCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMailingPostalCode.ClientID + "','" + rfvMailingPostalCode.ClientID + "','" + revMailingPostalCode.ClientID + "')");

            rdoBankIn.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            rdoCreditCard.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            #endregion

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/quote-results.aspx", Page);
            //hplTopBack.NavigateUrl = _redirectUrl;
            //hplBottomBack.NavigateUrl = _redirectUrl;
            if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentBuyOnly] != null)
            {
                if (Session[CE.Global.General.AgentBuyOnly].ToString() == "1")
                {
                    hplTopBack.Visible = false;
                    hplBottomBack.Visible = false;
                    hplTopCancel.Visible = true;
                    hplBottomCancel.Visible = true;
                }
                else
                {
                    hplTopBack.Visible = true;
                    hplBottomBack.Visible = true;
                    hplTopCancel.Visible = true;
                    hplBottomCancel.Visible = true;
                }
            }
            else
            {
                hplTopBack.Visible = true;
                hplBottomBack.Visible = true;
                hplTopCancel.Visible = false;
                hplBottomCancel.Visible = false;
            }
        }
        if (rdoBankIn.Checked || rdoCreditCard.Checked) txtPaymentType.Text = "1";
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (Session[CE.Global.General.CarResultId] != null)
        {
            if (!CheckConfirmStatus())
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
            if (Session[General.ProviderCompanyId].ToString() != "32")
            {
                if (Session[CE.Global.General.UserId] != null)
                {
                    _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                    Response.Redirect(_redirectUrl);
                }
                else
                {
                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/default.aspx", Page);
                    Response.Redirect(_redirectUrl);
                }
            }
        }
        else
        {
            if (Session[CE.Global.General.UserId] != null)
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/default.aspx", Page);
                Response.Redirect(_redirectUrl);
            }
        }


        if (txtName.Text == string.Empty)
        {
            lblMessage.Text = "Unfortunately, you are unable to proceed to complete this online proposal form.";
        }
        else
        {
            CheckValidation();
            ChangeValidationEffectServerSide("proposal");
            if (IsValid)
            {
                Int64 _carmoreresult = 0;
                Int64 driverresult = 0;
                BKICarMoreDetail _bkicarmoredetail = new BKICarMoreDetail();
                BKICarMoreDetailDB _bkicarmoredetaildb = new BKICarMoreDetailDB();

                if (Session[General.CarMoreDetailId] != null)
                {
                    _bkicarmoredetail.CECarMoreDetailId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());
                }
                else
                {
                    _bkicarmoredetail.CECarMoreDetailId = 0;
                }
                _bkicarmoredetail.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                _bkicarmoredetail.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());

                float _VarPremium = Convert.ToSingle(txtPremium.Text);
                float _VarCtpl = Convert.ToSingle(txtCTPL.Text);
                if (chkBuyCTPL.Checked)
                {
                    _bkicarmoredetail.AnnualPremium = _VarPremium + _VarCtpl;
                }
                else
                {
                    _bkicarmoredetail.AnnualPremium = _VarPremium;
                }
                _bkicarmoredetail.TermPremium = (_bkicarmoredetail.AnnualPremium / 4);

                //_bkicarmoredetail.AnnualPremium = Convert.ToSingle(txtPremium.Text);
                _bkicarmoredetail.Name = txtName.Text.Trim();
                _bkicarmoredetail.IdentificationNo = txtIdentificationNo.Text.Trim();
                _bkicarmoredetail.Occupation = ddlOccupation.GetOccupation();
                _bkicarmoredetail.ContactNo = txtContactNo.GetPhoneNo();
                _bkicarmoredetail.OfficePhoneNo = txtHomeOfficeNo.Text; //txtOfficePhoneNo.GetPhoneNo();
                //_bkicarmoredetail.LicenseNo = txtLicenseNo.Text;
                _bkicarmoredetail.BeneficiaryName = txtBeneficiaryName.Text;

                _bkicarmoredetail.CarPlate = txtCarPlate.Text;
                _bkicarmoredetail.CarPlateProvince = txtCarPlateProvince.Text;
                _bkicarmoredetail.PresentAddress = txtPresentAddress.Text;
                _bkicarmoredetail.SubDistrict = txtSubDistrict.Text;
                _bkicarmoredetail.District = txtDistrict.Text;
                _bkicarmoredetail.Province = txtProvince.Text;
                _bkicarmoredetail.PostalCode = txtPostalCode.Text;

                _bkicarmoredetail.IsMailingAddressDiff = rdoMailingAddressNo.Checked;
                _bkicarmoredetail.MailingAddress = txtMailingAddress.Text;
                _bkicarmoredetail.MailingSubDistrict = txtMailingSubDistrict.Text;
                _bkicarmoredetail.MailingDistrict = txtMailingDistrict.Text;
                _bkicarmoredetail.MailingProvince = txtMailingProvince.Text;
                _bkicarmoredetail.MailingPostalCode = txtMailingPostalCode.Text;
                _bkicarmoredetail.EngineNumber = txtEngineNumber.Text;
                _bkicarmoredetail.ChassisNumber = txtChassisNumber.Text;
                //_bkicarmoredetail.IsRegisteredOwner = rdoROwnerYes.Checked;
                _bkicarmoredetail.IsCTPL = chkBuyCTPL.Checked;
                _bkicarmoredetail.CTPL = Convert.ToSingle(txtCTPL.Text);
                if (rdoBankIn.Checked == true)
                {
                    _bkicarmoredetail.PaymentType = "Bank In";
                    switch (rdoBankInOption.SelectedItem.Value)
                    {
                        case "BKK":
                            _bkicarmoredetail.PaymentBank = "BKK";
                            break;
                        case "KBANK":
                            _bkicarmoredetail.PaymentBank = "KBANK";
                            break;
                        case "KTB":
                            _bkicarmoredetail.PaymentBank = "KTB";
                            break;
                        case "SCB":
                            _bkicarmoredetail.PaymentBank = "SCB";
                            break;
                    }
                }
                else if (rdoCreditCard.Checked == true)
                {
                    _bkicarmoredetail.PaymentType = "CreditCard";
                }
                _bkicarmoredetail.OrderRefNoId = GetOrderRefNoId();
                _bkicarmoredetail.OrderRefNo = GetOrderRefNo();
                _bkicarmoredetail.PaymentStatus = false;

                _bkicarmoredetail.QuoteRefNo = lblQRefNo.Text.Trim();

                if (Session[CE.Global.General.UserId] != null)
                {
                    _bkicarmoredetail.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _bkicarmoredetail.RefCEUserId = 0;
                }

                _bkicarmoredetail.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _bkicarmoredetail.Status = true;
                _bkicarmoredetail.CarResultId = Convert.ToInt64(Session[General.CarResultId].ToString());
                if (Session[CE.Global.General.AgentId] != null)
                {
                    _bkicarmoredetail.Ninfo4 = Convert.ToInt64(Session[CE.Global.General.AgentId].ToString());
                    if (rdoBankIn.Checked == true)
                    {
                        _bkicarmoredetail.Ninfo5 = 102;
                    }
                    else if (rdoCreditCard.Checked == true)
                    {
                        _bkicarmoredetail.Ninfo5 = 202;
                    }
                }
                else
                {
                    _bkicarmoredetail.Ninfo4 = 0;
                    _bkicarmoredetail.Ninfo5 = 0;
                }

                _carmoreresult = _bkicarmoredetaildb.Insert(_bkicarmoredetail);

                if (_carmoreresult > 0)
                {
                    //[Yui] @13/09/2013
                    if (lblSelectInsurer.Text.Trim() == "GluayGluay.com Special")
                        SaveConfirmDisclaimer(int.Parse(Session[General.ProviderCompanyId].ToString()), _carmoreresult);
                    //--- End ---

                    Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                    Int64 _paymentresult = 0;
                    _paymentresult = 1;
                    if (_paymentresult > 0)
                    {
                        if (txtDriverCount.Text.Trim() != "0")
                        {
                            if (!UpdateDriverDetails())
                            {
                                lblMessage.Text = "Car Drivers failed to save!";
                            }
                            else
                            {
                                driverresult = 1;
                            }
                        }
                        else
                        {
                            driverresult = 1;
                        }

                        if (driverresult > 0)
                        {
                            Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                            UserConfirmation _userconfirm = new UserConfirmation();
                            UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                            _userconfirm.ConfirmationType = "CI";
                            _userconfirm.CurrentStep = 4;
                            _userconfirm.UserSelectedId = Convert.ToInt64(Session[General.CarResultId].ToString());
                            _userconfirm.FirstStepId = Convert.ToInt64(Session[General.CarId].ToString());
                            if (Session[General.UserId] != null)
                            {
                                _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                            }
                            else
                            {
                                _userconfirm.RefCEUserId = 0;
                            }
                            _userconfirm.IsConfirm = true;
                            _userconfirm.ResultStatus = "Complete";
                            _userconfirm.IsComplete = true;
                            Int64 _result = _userconfirmdb.Insert(_userconfirm);
                            if (_result > 0)
                            {
                                string _provideid = Encode(Session[General.ProviderCompanyId].ToString());
                                string _refid = "";
                                string convertno = General.GetRefNumber(Convert.ToInt64(Session[CE.Global.General.CarId]));
                                _refid = "A" + convertno;

                                if (Session[General.CarResultId] != null)
                                {
                                    SendProposalToAgent(Session[General.CarResultId].ToString());
                                }
                                if (rdoBankIn.Checked)
                                {
                                    ProposalNotification();
                                    General.ClearAllSession(this.Page, "ALL");
                                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/usermessage.aspx", Page);
                                    Session["CIMSG"] = _provideid + "," + _refid + "," + "OTHER";
                                    Response.Redirect(_redirectUrl);
                                }
                                else if (rdoCreditCard.Checked)
                                {
                                    float _fAmount = _bkicarmoredetail.AnnualPremium;
                                    //float _fAmount = Convert.ToSingle(txtPremium.Text);
                                    string _strAmount, eAmount, _strOrderRefNo, eOrderRefNo;
                                    _strAmount = ""; eAmount = ""; _strOrderRefNo = ""; eOrderRefNo = "";
                                    string key = "cxDAtravel";
                                    CXDecryption.Decryption cxd = new CXDecryption.Decryption();
                                    _strAmount = _fAmount.ToString();
                                    _strOrderRefNo = _bkicarmoredetail.OrderRefNo;
                                    if (_strAmount.ToString() != "" && _strAmount.ToString() != null)
                                    {
                                        byte[] Amount = cxd.Encrypt(_strAmount, key);
                                        eAmount = Convert.ToBase64String(Amount);
                                    }
                                    if (_strOrderRefNo.ToString() != "" && _strOrderRefNo.ToString() != null)
                                    {
                                        byte[] OrderRefNo = cxd.Encrypt(_strOrderRefNo, key);
                                        eOrderRefNo = Convert.ToBase64String(OrderRefNo);
                                    }
                                    string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString();
                                    URL += "?pa=" + eAmount + "&orno=" + eOrderRefNo;
                                    Response.Redirect(URL);
                                }
                            }
                            else
                            {
                                lblMessage.Text = "Can't update confirmation status.";
                            }
                        }
                    }
                }
            }
        }
    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/car-insurance/results.aspx?sortby=Premium");
    }

    public void LoadCarPolicyDetails()
    {
        if (Session[CE.Global.General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else
        {
            _UserId = 0;
        }
        _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
        _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());

        DataSet _dtProvider = new DataSet();
        BKICarMoreDetail _bkicarmoredetail = new BKICarMoreDetail();
        BKICarMoreDetailDB _bkicarmoredetaildb = new BKICarMoreDetailDB();
        _dtProvider = _bkicarmoredetaildb.GetCarPolicyDetails(_CarId, _UserId, _CXCTypeId, _ProviderId);
        if (_dtProvider != null && _dtProvider.Tables.Count > 0)
        {
            if (_dtProvider.Tables[0].Rows.Count > 0 && _dtProvider.Tables[1].Rows.Count > 0 && _dtProvider.Tables[2].Rows.Count > 0)
            {
                lblYrofManufacture.Text = _dtProvider.Tables[0].Rows[0]["ManufactYear"].ToString();
                lblCarModelYear.Text = _dtProvider.Tables[0].Rows[0]["RegYear"].ToString();
                lblCarMakemodel.Text = _dtProvider.Tables[0].Rows[0]["MakeModelDesc"].ToString();
                lblRedPlate.Text = _dtProvider.Tables[0].Rows[0]["RedPlate"].ToString();
                lblCTPL.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString();
                lblCTPLAmount.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString() + " " + Resources.CarInsurance.Baht;
                txtCTPL.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString();
                lblNCB.Text = _dtProvider.Tables[0].Rows[0]["NCDPercent"].ToString() + "%";
                float _InsuredAmt = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["SumInsured"].ToString());
                if (_InsuredAmt > 0)
                {
                    lblSumInsured.Text = String.Format("{0:0,0}", _InsuredAmt) + " " + Resources.CarInsurance.Baht;  //String.Format("฿{0:0,0.00}", _InsuredAmt);
                }
                else
                {
                    lblSumInsured.Text = "N/A";
                }
                txtDriverCount.Text = _dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString();

                EnableDriverPanels();
                lblCommencementdate.Text = "";
                if (_dtProvider.Tables[0].Rows[0]["CommenceDate"].ToString() != "")
                {
                    lblCommencementdate.Text = Convert.ToDateTime(_dtProvider.Tables[0].Rows[0]["CommenceDate"]).ToString("dd-MMM-yyyy");
                }

                if (_dtProvider.Tables[1].Rows[0]["PlanName"].ToString() != "GluayGluay.com Special")
                {
                    lblSelectInsurer.Text = _dtProvider.Tables[1].Rows[0]["CompanyName"].ToString();
                    lblPackages.Text = _dtProvider.Tables[1].Rows[0]["PlanName"].ToString();

                    //[Yui] @13/09/2013
                    cust_Disclaimer.Enabled = false;
                }
                else
                {
                    lblInsurance.Text = Resources.ProposalForm.Package;
                    lblSelectInsurer.Text = _dtProvider.Tables[1].Rows[0]["PlanName"].ToString();
                    lblPackageName.Text = Resources.ProposalForm.PackageCondition;
                    lblPackages.Text = Resources.CarInsuranceResultPage.SpecialNCB;

                    //[Yui] @13/09/2013 
                    divDisclaimerTab.Style.Add("display", "");
                }

                //float _APremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Hide for Sop Request on 12 Sep 2011 by Skype
                float _APremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Change for Sop Request on 12 Sep 2011 by Skype
                lblPremiums.Text = String.Format("{0:0,0.00}", _APremium) + " " + Resources.CarInsurance.Baht;//String.Format("฿{0:0,0.00}", _APremium);
                //txtPremium.Text = _dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString();//Hide for Sop Request on 12 Sep 2011 by Skype
                txtPremium.Text = _dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString();//Hide for Sop Request on 12 Sep 2011 by Skype
                
                float _Promotion = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString());
                lblPromotion.Text = String.Format("{0:0,0.00}", _Promotion) + " " + Resources.CarInsurance.Baht;

                //float _VarPremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Hide for Sop Request on 12 Sep 2011 by Skype
                float _VarPremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString());//Change for Sop Request on 12 Sep 2011 by Skype
                float _VarCtpl = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["CTPL"].ToString());
                float _VarTotalPremiumPlusCtpl = _VarPremium + _VarCtpl;
                lblTotalPremiumPlusCtpl.Text = String.Format("{0:0,0.00}", _VarTotalPremiumPlusCtpl) + " " + Resources.CarInsurance.Baht;
                lblTotalPremium.Text = String.Format("{0:0,0.00}", _VarPremium) + " " + Resources.CarInsurance.Baht;
                float __VarMonthlyPremiumPlusCtpl = _VarTotalPremiumPlusCtpl / 4;
                float __VarMonthlyPremium = _VarPremium / 4;
                lblPremiumMonthlyPlusCtpl.Text = String.Format("{0:0,0.00}", __VarMonthlyPremiumPlusCtpl) + " " + Resources.CarInsurance.Baht + " (" + Resources.ProposalForm.PerMonth + ")";
                lblPremiumMonthly.Text = String.Format("{0:0,0.00}", __VarMonthlyPremium) + " " + Resources.CarInsurance.Baht + " (" + Resources.ProposalForm.PerMonth + ")";

                //Sakthi - for Sop Request on 12 Sep 2011 by Skype -- Start
                string IsIncludeCMI = _dtProvider.Tables[1].Rows[0]["IsIncludeCMI"].ToString();
                if (IsIncludeCMI == "True" || IsIncludeCMI == "1")
                {
                    txtIsIncludeCMI.Text = "1";
                }
                else
                {
                    txtIsIncludeCMI.Text = "0";
                }
                //Sakthi - for Sop Request on 12 Sep 2011 by Skype -- End

                string convertno = General.GetRefNumber(_CarId);
                if (_dtProvider.Tables[1].Rows[0]["PlanName"].ToString() != "GluayGluay.com Special")
                {
                    if (_ProviderId == 11)
                    {
                        lblQRefNo.Text = "AZC" + convertno.ToString();
                    }
                    else if (_ProviderId == 12)
                    {
                        lblQRefNo.Text = "MSI" + convertno.ToString();
                    }
                    else if (_ProviderId == 16)
                    {
                        lblQRefNo.Text = "AXA" + convertno.ToString();
                    }
                    else if (_ProviderId == 29)
                    {
                        lblQRefNo.Text = "LMG" + convertno.ToString();
                    }
                    else if (_ProviderId == 31)
                    {
                        lblQRefNo.Text = "CTS" + convertno.ToString();
                    }
                    else if (_ProviderId == 32)
                    {
                        lblQRefNo.Text = "BKI" + convertno.ToString();
                    }
                }
                else
                {
                    lblQRefNo.Text = "GG" + _ProviderId.ToString() + convertno.ToString();
                }

                if (_dtProvider.Tables[3].Rows.Count > 0)
                {
                    ddlOccupation.Occupation = _dtProvider.Tables[3].Rows[0]["Occupation"].ToString();
                }
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/usermessage.aspx", Page);
                Session["UMMSG"] = "CI,502";
                Response.Redirect(_redirectUrl);
            }
        }
        else
        {
            _redirectUrl = CE.Global.General.GetUrl("~/user/usermessage.aspx", Page);
            Session["UMMSG"] = "CI,502";
            Response.Redirect(_redirectUrl);
        }
        LoadCarDrivers();
    }

    private void LoadCarDrivers()
    {
        ddlDriverDOB1.StartYear = General.GetUTCDateTime().Year - 100;
        ddlDriverDOB1.EndYear = General.GetUTCDateTime().Year - 18;
        ddlDriverDOB2.StartYear = General.GetUTCDateTime().Year - 100;
        ddlDriverDOB2.EndYear = General.GetUTCDateTime().Year - 18;
        ddlDriverDOB3.StartYear = General.GetUTCDateTime().Year - 100;
        ddlDriverDOB3.EndYear = General.GetUTCDateTime().Year - 18;
        ddlDriverDOB4.StartYear = General.GetUTCDateTime().Year - 100;
        ddlDriverDOB4.EndYear = General.GetUTCDateTime().Year - 18;
        ddlDriverDOB5.StartYear = General.GetUTCDateTime().Year - 100;
        ddlDriverDOB5.EndYear = General.GetUTCDateTime().Year - 18;

        CarDriverDB _cardriverdb = new CarDriverDB();
        _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        if (Session[CE.Global.General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else
        {
            _UserId = 0;
        }
        DataTable _driverList = _cardriverdb.GetDriverList(_CarId, _UserId);
        if (_driverList.Rows.Count > 0)
        {
            lblDriverId1.Text = _driverList.Rows[0]["CarDriverId"].ToString();

            _dtDOB1 = Convert.ToDateTime(_driverList.Rows[0]["DOB"].ToString());
            ddlDriverDOB1.Day = _dtDOB1.Day;
            ddlDriverDOB1.Month = _dtDOB1.Month;
            ddlDriverDOB1.Year = _dtDOB1.Year;
            ddlDriverDOB1.IsEnabled = false;

            if (_driverList.Rows[0]["Surname"].ToString() != null && _driverList.Rows[0]["Surname"].ToString() != "")
            {
                txtDriverSurName1.Text = _driverList.Rows[0]["Surname"].ToString();
            }
            if (_driverList.Rows[0]["GivenName"].ToString() != null && _driverList.Rows[0]["GivenName"].ToString() != "")
            {
                txtDriverGivenName1.Text = _driverList.Rows[0]["GivenName"].ToString();
            }
        }
        if (_driverList.Rows.Count > 1)
        {
            lblDriverId2.Text = _driverList.Rows[1]["CarDriverId"].ToString();

            _dtDOB2 = Convert.ToDateTime(_driverList.Rows[1]["DOB"].ToString());
            ddlDriverDOB2.Day = _dtDOB2.Day;
            ddlDriverDOB2.Month = _dtDOB2.Month;
            ddlDriverDOB2.Year = _dtDOB2.Year;
            ddlDriverDOB2.IsEnabled = false;

            if (_driverList.Rows[1]["Surname"].ToString() != null && _driverList.Rows[1]["Surname"].ToString() != "")
            {
                txtDriverSurName2.Text = _driverList.Rows[1]["Surname"].ToString();
            }
            if (_driverList.Rows[1]["GivenName"].ToString() != null && _driverList.Rows[1]["GivenName"].ToString() != "")
            {
                txtDriverGivenName2.Text = _driverList.Rows[1]["GivenName"].ToString();
            }
        }
        if (_driverList.Rows.Count > 2)
        {
            lblDriverId3.Text = _driverList.Rows[2]["CarDriverId"].ToString();

            _dtDOB3 = Convert.ToDateTime(_driverList.Rows[2]["DOB"].ToString());
            ddlDriverDOB3.Day = _dtDOB3.Day;
            ddlDriverDOB3.Month = _dtDOB3.Month;
            ddlDriverDOB3.Year = _dtDOB3.Year;
            ddlDriverDOB3.IsEnabled = false;

            if (_driverList.Rows[2]["Surname"].ToString() != null && _driverList.Rows[2]["Surname"].ToString() != "")
            {
                txtDriverSurName3.Text = _driverList.Rows[2]["Surname"].ToString();
            }
            if (_driverList.Rows[2]["GivenName"].ToString() != null && _driverList.Rows[2]["GivenName"].ToString() != "")
            {
                txtDriverGivenName3.Text = _driverList.Rows[2]["GivenName"].ToString();
            }
        }
        if (_driverList.Rows.Count > 3)
        {
            lblDriverId4.Text = _driverList.Rows[3]["CarDriverId"].ToString();

            _dtDOB4 = Convert.ToDateTime(_driverList.Rows[3]["DOB"].ToString());
            ddlDriverDOB4.Day = _dtDOB4.Day;
            ddlDriverDOB4.Month = _dtDOB4.Month;
            ddlDriverDOB4.Year = _dtDOB4.Year;
            ddlDriverDOB4.IsEnabled = false;

            if (_driverList.Rows[3]["Surname"].ToString() != null && _driverList.Rows[3]["Surname"].ToString() != "")
            {
                txtDriverSurName4.Text = _driverList.Rows[3]["Surname"].ToString();
            }
            if (_driverList.Rows[3]["GivenName"].ToString() != null && _driverList.Rows[3]["GivenName"].ToString() != "")
            {
                txtDriverGivenName4.Text = _driverList.Rows[3]["GivenName"].ToString();
            }
        }
        if (_driverList.Rows.Count > 4)
        {
            lblDriverId5.Text = _driverList.Rows[4]["CarDriverId"].ToString();

            _dtDOB5 = Convert.ToDateTime(_driverList.Rows[4]["DOB"].ToString());
            ddlDriverDOB5.Day = _dtDOB5.Day;
            ddlDriverDOB5.Month = _dtDOB5.Month;
            ddlDriverDOB5.Year = _dtDOB5.Year;
            ddlDriverDOB5.IsEnabled = false;

            if (_driverList.Rows[4]["Surname"].ToString() != null && _driverList.Rows[4]["Surname"].ToString() != "")
            {
                txtDriverSurName5.Text = _driverList.Rows[4]["Surname"].ToString();
            }
            if (_driverList.Rows[4]["GivenName"].ToString() != null && _driverList.Rows[4]["GivenName"].ToString() != "")
            {
                txtDriverGivenName5.Text = _driverList.Rows[4]["GivenName"].ToString();
            }
        }
    }

    private bool UpdateDriverDetails()
    {
        bool _result = false;
        CarDriver _cardriver = new CarDriver();
        CarDriverDB _cardriverdb = new CarDriverDB();

        if (txtDriverCount.Text.Trim() != "0")
        {
            int _drivercount = Convert.ToInt32(txtDriverCount.Text.Trim());
            int _insertcount = 0;

            for (int i = 1; i <= _drivercount; i++)
            {
                _cardriver.StepId = 2;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _cardriver.RerCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _cardriver.RerCEUserId = 0;
                }
                _cardriver.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                if (i == 1)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId1.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName1.Text.Trim()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName1.Text.Trim()));
                    _cardriver.DOB = _dtDOB1;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber1.Text.Trim()));
                    _cardriver.Status = "Active";
                }
                else if (i == 2)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId2.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName2.Text.Trim()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName2.Text.Trim()));
                    _cardriver.DOB = _dtDOB2;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber2.Text.Trim()));
                    _cardriver.Status = "Active";
                }
                else if (i == 3)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId3.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName3.Text.Trim()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName3.Text.Trim()));
                    _cardriver.DOB = _dtDOB3;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber3.Text.Trim()));
                    _cardriver.Status = "Active";
                }
                else if (i == 4)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId4.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName4.Text.Trim()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName4.Text.Trim()));
                    _cardriver.DOB = _dtDOB4;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber4.Text.Trim()));
                    _cardriver.Status = "Active";
                }
                else if (i == 5)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId5.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName5.Text.Trim()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName5.Text.Trim()));
                    _cardriver.DOB = _dtDOB5;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber5.Text.Trim()));
                    _cardriver.Status = "Active";
                }
                _cardriver.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                if (_cardriverdb.Insert(_cardriver) > 0)
                {
                    _insertcount++;
                    _result = true;
                }
            }
            _cardriverdb = null;
            _cardriver = null;
        }
        return _result;
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("CI", Request, "Car Insurance AZCp proposal form.");
    }

    private void CheckValidation()
    {
        //ClearScriptTag
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtIdentificationNo.Text = General.ClearScriptTag(txtIdentificationNo.Text);
        //txtLicenseNo.Text = General.ClearScriptTag(txtLicenseNo.Text);
        txtBeneficiaryName.Text = General.ClearScriptTag(txtBeneficiaryName.Text);
        txtCarPlate.Text = General.ClearScriptTag(txtCarPlate.Text);
        txtCarPlateProvince.Text = General.ClearScriptTag(txtCarPlateProvince.Text);
        txtPresentAddress.Text = General.ClearScriptTag(txtPresentAddress.Text);
        txtSubDistrict.Text = General.ClearScriptTag(txtSubDistrict.Text);
        txtDistrict.Text = General.ClearScriptTag(txtDistrict.Text);
        txtProvince.Text = General.ClearScriptTag(txtProvince.Text);
        txtPostalCode.Text = General.ClearScriptTag(txtPostalCode.Text);
        txtMailingAddress.Text = General.ClearScriptTag(txtMailingAddress.Text);
        txtMailingSubDistrict.Text = General.ClearScriptTag(txtMailingSubDistrict.Text);
        txtMailingDistrict.Text = General.ClearScriptTag(txtMailingDistrict.Text);
        txtMailingProvince.Text = General.ClearScriptTag(txtMailingProvince.Text);
        txtMailingPostalCode.Text = General.ClearScriptTag(txtMailingPostalCode.Text);
        txtEngineNumber.Text = General.ClearScriptTag(txtEngineNumber.Text);
        txtChassisNumber.Text = General.ClearScriptTag(txtChassisNumber.Text);
        txtHomeOfficeNo.Text = General.ClearScriptTag(txtHomeOfficeNo.Text);

        //HtmlEncode
        txtName.Text = Server.HtmlEncode(txtName.Text);
        txtIdentificationNo.Text = Server.HtmlEncode(txtIdentificationNo.Text);
        //txtLicenseNo.Text = Server.HtmlEncode(txtLicenseNo.Text);
        txtBeneficiaryName.Text = Server.HtmlEncode(txtBeneficiaryName.Text);
        txtCarPlate.Text = Server.HtmlEncode(txtCarPlate.Text);
        txtCarPlateProvince.Text = Server.HtmlEncode(txtCarPlateProvince.Text);
        txtPresentAddress.Text = Server.HtmlEncode(txtPresentAddress.Text);
        txtSubDistrict.Text = Server.HtmlEncode(txtSubDistrict.Text);
        txtDistrict.Text = Server.HtmlEncode(txtDistrict.Text);
        txtProvince.Text = Server.HtmlEncode(txtProvince.Text);
        txtPostalCode.Text = Server.HtmlEncode(txtPostalCode.Text);
        txtMailingAddress.Text = Server.HtmlEncode(txtMailingAddress.Text);
        txtMailingSubDistrict.Text = Server.HtmlEncode(txtMailingSubDistrict.Text);
        txtMailingDistrict.Text = Server.HtmlEncode(txtMailingDistrict.Text);
        txtMailingProvince.Text = Server.HtmlEncode(txtMailingProvince.Text);
        txtMailingPostalCode.Text = Server.HtmlEncode(txtMailingPostalCode.Text);
        txtEngineNumber.Text = Server.HtmlEncode(txtEngineNumber.Text);
        txtChassisNumber.Text = Server.HtmlEncode(txtChassisNumber.Text);
        txtHomeOfficeNo.Text = Server.HtmlEncode(txtHomeOfficeNo.Text);
    }

    private void ChangeRequiredFieldValidation(WebControl ctl, RequiredFieldValidator rfv, string strValidation)
    {
        if (rfv.Enabled && rfv.ValidationGroup == strValidation)
        {
            rfv.Validate();
            if (rfv.IsValid == false)
            {
                ctl.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ctl.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ctl.ControlStyle.CssClass = "";
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Proposal Details
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        //IdentificationNo
        if (rfvIdentificationNo.Enabled && rfvIdentificationNo.ValidationGroup == strValidationGroup)
        {
            rfvIdentificationNo.Validate();
            if (rfvIdentificationNo.IsValid == false)
            {
                txtIdentificationNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtIdentificationNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtIdentificationNo.ControlStyle.CssClass = "";
        }

        if (revIdentificationNo.Enabled && revIdentificationNo.ValidationGroup == strValidationGroup)
        {
            if (rfvIdentificationNo.IsValid)
            {
                revIdentificationNo.Validate();
                if (revIdentificationNo.IsValid == false)
                {
                    txtIdentificationNo.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtIdentificationNo.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtIdentificationNo.ControlStyle.CssClass = "";
        }
        //Applicant's Occupation
        ddlOccupation.ChangeValidationEffectServerSide(strValidationGroup);
        //Applicant's Contact No
        txtContactNo.ChangeValidationEffectServerSide(strValidationGroup);
        //Applicant's Office No
        //txtOfficePhoneNo.ChangeValidationEffectServerSide(strValidationGroup);

        //BeneficiaryName
        if (rfvBeneficiaryName.Enabled && rfvBeneficiaryName.ValidationGroup == strValidationGroup)
        {
            rfvBeneficiaryName.Validate();
            if (rfvBeneficiaryName.IsValid == false)
            {
                txtBeneficiaryName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtBeneficiaryName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtBeneficiaryName.ControlStyle.CssClass = "";
        }

        if (revBeneficiaryName.Enabled && revBeneficiaryName.ValidationGroup == strValidationGroup)
        {
            if (rfvBeneficiaryName.IsValid)
            {
                revBeneficiaryName.Validate();
                if (revBeneficiaryName.IsValid == false)
                {
                    txtBeneficiaryName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtBeneficiaryName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtBeneficiaryName.ControlStyle.CssClass = "";
        }

        //CarPlate
        if (rfvCarPlate.Enabled && rfvCarPlate.ValidationGroup == strValidationGroup)
        {
            rfvCarPlate.Validate();
            if (rfvCarPlate.IsValid == false)
            {
                txtCarPlate.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCarPlate.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCarPlate.ControlStyle.CssClass = "";
        }

        //CarPlate Province
        if (rfvCarPlateProvince.Enabled && rfvCarPlateProvince.ValidationGroup == strValidationGroup)
        {
            rfvCarPlateProvince.Validate();
            if (rfvCarPlateProvince.IsValid == false)
            {
                txtCarPlateProvince.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCarPlateProvince.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCarPlateProvince.ControlStyle.CssClass = "";
        }

        //PresentAddress
        if (rfvPresentAddress.Enabled && rfvPresentAddress.ValidationGroup == strValidationGroup)
        {
            rfvPresentAddress.Validate();
            if (rfvPresentAddress.IsValid == false)
            {
                txtPresentAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPresentAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPresentAddress.ControlStyle.CssClass = "";
        }

        //Sub District
        if (rfvSubDistrict.Enabled && rfvSubDistrict.ValidationGroup == strValidationGroup)
        {
            rfvSubDistrict.Validate();
            if (rfvSubDistrict.IsValid == false)
            {
                txtSubDistrict.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSubDistrict.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSubDistrict.ControlStyle.CssClass = "";
        }

        //District
        if (rfvDistrict.Enabled && rfvDistrict.ValidationGroup == strValidationGroup)
        {
            rfvDistrict.Validate();
            if (rfvDistrict.IsValid == false)
            {
                txtDistrict.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDistrict.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDistrict.ControlStyle.CssClass = "";
        }

        //Province
        if (rfvProvince.Enabled && rfvProvince.ValidationGroup == strValidationGroup)
        {
            rfvProvince.Validate();
            if (rfvProvince.IsValid == false)
            {
                txtProvince.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtProvince.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtProvince.ControlStyle.CssClass = "";
        }

        //Postal Code
        if (rfvPostalCode.Enabled && rfvPostalCode.ValidationGroup == strValidationGroup)
        {
            rfvPostalCode.Validate();
            if (rfvPostalCode.IsValid == false)
            {
                txtPostalCode.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPostalCode.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPostalCode.ControlStyle.CssClass = "";
        }

        if (revPostalCode.Enabled && revPostalCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostalCode.IsValid)
            {
                revPostalCode.Validate();
                if (revPostalCode.IsValid == false)
                {
                    txtPostalCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtPostalCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtPostalCode.ControlStyle.CssClass = "";
        }
        #endregion

        #region MailingAddress
        ChangeRequiredFieldValidation(txtMailingAddress, rfvMailingAddress, strValidationGroup);
        ChangeRequiredFieldValidation(txtMailingSubDistrict, rfvMailingSubDistrict, strValidationGroup);
        ChangeRequiredFieldValidation(txtMailingDistrict, rfvMailingDistrict, strValidationGroup);
        ChangeRequiredFieldValidation(txtMailingProvince, rfvMailingProvince, strValidationGroup);
        ChangeRequiredFieldValidation(txtMailingPostalCode, rfvMailingPostalCode, strValidationGroup);
        if (revMailingPostalCode.Enabled && revMailingPostalCode.ValidationGroup == strValidationGroup)
        {
            if (rfvMailingPostalCode.IsValid)
            {
                revMailingPostalCode.Validate();
                if (revMailingPostalCode.IsValid == false)
                {
                    txtMailingPostalCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtMailingPostalCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtMailingPostalCode.ControlStyle.CssClass = "";
        }
        #endregion

        #region Payment Mode

        //PaymentType
        if (rfvPaymentType.Enabled && rfvPaymentType.ValidationGroup == strValidationGroup)
        {
            rfvPaymentType.Validate();
            if (rfvPaymentType.IsValid == false)
            {
                lblBankIn.ControlStyle.CssClass = "validationError";
                lblCreditCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblBankIn.ControlStyle.CssClass = "";
                lblCreditCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblBankIn.ControlStyle.CssClass = "";
            lblCreditCard.ControlStyle.CssClass = "";
        }

        #endregion

        #region Drivers
        //Driver 1 **************************************************************
        //Name
        if (rfvDriverSurName1.Enabled && rfvDriverSurName1.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName1.Validate();
            if (rfvDriverSurName1.IsValid == false)
            {
                txtDriverSurName1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName1.ControlStyle.CssClass = "";
        }

        //Driver 2 **************************************************************
        //Name
        if (rfvDriverSurName2.Enabled && rfvDriverSurName2.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName2.Validate();
            if (rfvDriverSurName2.IsValid == false)
            {
                txtDriverSurName2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName2.ControlStyle.CssClass = "";
        }

        //Driver 3 **************************************************************
        //Name
        if (rfvDriverSurName3.Enabled && rfvDriverSurName3.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName3.Validate();
            if (rfvDriverSurName3.IsValid == false)
            {
                txtDriverSurName3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName3.ControlStyle.CssClass = "";
        }

        //Driver 4 **************************************************************
        //Name
        if (rfvDriverSurName4.Enabled && rfvDriverSurName4.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName4.Validate();
            if (rfvDriverSurName4.IsValid == false)
            {
                txtDriverSurName4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName4.ControlStyle.CssClass = "";
        }

        //Driver 5 **************************************************************
        //Name
        if (rfvDriverSurName5.Enabled && rfvDriverSurName5.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName5.Validate();
            if (rfvDriverSurName5.IsValid == false)
            {
                txtDriverSurName5.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName5.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName5.ControlStyle.CssClass = "";
        }

        #endregion

    }

    private void EnableCreditCardControls(bool isEnable)
    {
    }

    private void EnableDriverPanels()
    {
        if (txtDriverCount.Text.Trim() == "0")
        {
            pnlDriverDetails.Visible = false;
            pnlDriver1.Visible = false;
            pnlDriver2.Visible = false;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(false);
            ValidateDriver2(false);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "1")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = false;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(false);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "2")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "3")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "4")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = true;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(true);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "5")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = true;
            pnlDriver5.Visible = true;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(true);
            ValidateDriver5(true);
        }
    }

    private void ValidateDriver1(bool OnOff)
    {
        rfvDriverSurName1.Enabled = OnOff;
    }

    private void ValidateDriver2(bool OnOff)
    {
        rfvDriverSurName2.Enabled = OnOff;
    }

    private void ValidateDriver3(bool OnOff)
    {
        rfvDriverSurName3.Enabled = OnOff;
    }

    private void ValidateDriver4(bool OnOff)
    {
        rfvDriverSurName4.Enabled = OnOff;
    }

    private void ValidateDriver5(bool OnOff)
    {
        rfvDriverSurName5.Enabled = OnOff;
    }

    private bool CheckConfirmStatus()
    {
        bool _retValue = false;
        Int64 _CarId = 0;
        BKICarMoreDetailDB _bkicarmoredetaildb = new BKICarMoreDetailDB();
        if (Session[General.CarId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        }
        Int64 _checkResult = _bkicarmoredetaildb.CheckConfirmStatus(_CarId, "CI");
        if (_checkResult > 0)
        {
            _retValue = true;
        }
        else
        {
            _retValue = false;
        }

        return _retValue;
    }

    private Int64 GetOrderRefNoId()
    {
        Int64 _retValue = 0;
        Int64 _OrderId = 0;
        if (Session[General.CarId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        }
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT OrderRefNoId FROM [tblCarMoreDetail_BKI] ORDER BY CECarMoreDetailId DESC ";
        object _result = _db.ExecuteScalarSqlStatement(strSql);
        if (_result != null)
        {
            _OrderId = Convert.ToInt64(_result.ToString());
        }
        _retValue = _OrderId + 1;

        return _retValue;
    }

    private void ProposalNotification()
    {
        string _strMailActive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsMailActive");
        if (_strMailActive == "1")
        {
            string _strSql, _providerName, _ToEmail, _CCEmail, _BCCEmail, _Date, _Time, _InsuranceName, _RefNo;
            MyDatabase _db = new MyDatabase();
            DataTable _dtProvider = new DataTable();
            DataTable _dtInsurance = new DataTable();
            _Date = "";
            _Time = "";
            _RefNo = "";
            _strSql = "";
            _providerName = "";
            _ToEmail = "";
            _CCEmail = "";
            _BCCEmail = "";
            _InsuranceName = Resources.WelcomeEmail.CarInsurance; //"Car Insurance";

            _ToEmail = Session[General.UserEmail].ToString();
            if (Session[General.ProviderCompanyId] != null && Session[General.CarId] != null)
            {
                _ProviderId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _CarId = Convert.ToInt64(Session[General.CarId].ToString());
            }
            _strSql = "SELECT [CompanyName], [Email1], [PhoneNo1] FROM tblProviderCompany WHERE ProviderCompanyId = " + _ProviderId.ToString();

            _dtProvider = _db.GetDataTable(_strSql);
            if (_dtProvider.Rows.Count > 0)
            {
                _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
                _CCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_CC");
                _BCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_BCC");
            }
            _strSql = "";
            _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
            _strSql += " FROM  tblCarMoreDetail_BKI WHERE CECarId = " + _CarId.ToString() + " ORDER BY ModifiedDate DESC";
            _dtInsurance = _db.GetDataTable(_strSql);
            if (_dtInsurance.Rows.Count > 0)
            {
                _Date = _dtInsurance.Rows[0]["Date"].ToString();
                _Time = _dtInsurance.Rows[0]["Time"].ToString();
            }
            _RefNo = lblQRefNo.Text.Trim();
            if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
            {
                if (Session[General.CarResultId] != null)
                {
                    SendProposalToUserNEW(Session[General.CarResultId].ToString());

                }
            }
        }
    }

    public string GetOrderRefNo()
    {
        Int64 CarId = 0;
        if (Session[CE.Global.General.CarId] != null)
            CarId = Convert.ToInt64(Session[CE.Global.General.CarId].ToString());
        string _result = "";
        string _onoffline = "1";
        string _firstno = General.GetUTCDateTime().ToString("yy") + General.GetUTCDateTime().Month.ToString("00") + General.GetUTCDateTime().Day.ToString("00") +
                          General.GetUTCDateTime().Hour.ToString("00") + General.GetUTCDateTime().Minute.ToString("00");
        _result = _firstno + _onoffline + CarId.ToString("000000000");
        return _result;
    }

    private string GetOrderRefNo_Old()
    {
        string _OrderNo = General.GetUTCDateTime().ToString("yy");
        string _RandomNo = "";
        int _len = Session[CE.Global.General.CarId].ToString().Length;
        int _randomlen = 9 - _len;
        Random random = new Random();
        for (int i = 0; i < _randomlen; i++)
        {
            _RandomNo += random.Next(0, 9).ToString();
        }
        _OrderNo = _OrderNo + _len + _RandomNo + Session[CE.Global.General.CarId].ToString();
        return _OrderNo;
    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool _status = true;
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
    }

    private void LoadCardExpiryMonth()
    {
    }

    private void LoadCardExpiryYear()
    {
    }

    private bool SendProposalToUserNEW(string CITempResultId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";

        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }

            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {

                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = Session[General.UserEmail].ToString();
        //string _emailTo = "sophon.vorasitchai@comparexpress.com";
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "<Online> - " + Resources.EmailMessage.Subject; // "Your Car Insurance Quotes on CompareXpress(Thailand)";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        //string _currentDomainUrl = "http://www.กล้วยๆ.com";
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.OrderConfirmation + "</strong><br /><br />";
        _mailBody += Resources.Proposal.ThankYou + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + "</strong> " + _refNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
        _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        _mailBody += "</table> <br /><br />";

        //Sakthi on 18 Jan 2012 -- Start
        DataSet _dsResults = new DataSet();
        DataView dvResults = new DataView();
        SortedList _sPara = new SortedList();

        _sPara.Add("@CarId", Convert.ToInt64(Session[General.CarId].ToString()));
        _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
        _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
        if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
        {
            dvResults = _dsResults.Tables[0].DefaultView;
            dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
        }
        //Sakthi on 18 Jan 2012 -- End

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

        DataTable dtResults = dvResults.ToTable();

        bool IsGGSpecial = false;
        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            //logo
            string logourl = "";
            string insurername = dtResults.Rows[0]["PackageName"].ToString();
            if (dtResults.Rows[0]["PackageName"].ToString() != "GluayGluay.com Special")
            {
                logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);
            }
            else
            {
                //[Yui] @13/09/2013
                IsGGSpecial = true;
                // --- End ---

                logourl = "/images/public/gluaygluay_logo.png";
                insurername += " (" + Resources.CarInsuranceResultPage.SpecialNCB + ")";
            }

            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";
                        
            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";
            
            float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
            string monthlyInstallment = "";

            if (_fMonthlyPremiumAmount > 0.0f)
            {
                string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
                monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
            }
            else
            {
                monthlyInstallment = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            //Deductible  
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.DEC + "</strong></td>";
            float _fDEC = Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
            string deductible = "";
            if (_fDEC > 0.0f)
            {
                deductible = String.Format("{0:0,0.00}", _fDEC);
            }
            else
            {
                deductible = Resources.CarInsuranceResultPage.Waived;  //"<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + deductible + "</td>";
            _mailBody += "</tr>";

            string suminsured = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString()));
            if (suminsured == "0")
            {
                suminsured = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            //Own Damage
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.OwnDamage + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + suminsured + "</td>";
            _mailBody += "</tr>";

            //Fire
            string fire = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString()));
            if (fire == "0")
            {
                fire = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Fire + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + fire + "</td>";
            _mailBody += "</tr>";

            //Theft
            string theft = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString()));
            if (theft == "0")
            {
                theft = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Theft + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + theft + "</td>";
            _mailBody += "</tr>";

            //TPPD
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.TPPD + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIA
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIA + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIP
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIP + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //PA Driver
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.PADriver + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</td>";
            _mailBody += "</tr>";

            int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
            string medicalExpense = "";

            if (_MedicalExpense == 0)
            {
                medicalExpense = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            else
            {
                medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
            }

            //Medical Expense
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.MED + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + medicalExpense + "</td>";
            _mailBody += "</tr>";

            //BB
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.BailBond + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //CTPL
            if (_isCTPL == "Yes")
            {
                //premium before ctpl
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.AnnualPremium + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

                double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);

                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

                //ctplamount
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.CTPL + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5;'>";

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

            }      

            //premium
            _mailBody += "<tr>";
            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

            if (_isCTPL == "No")
            {
                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
            }
            else
            {
                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</strong>";
            }
                        
            _mailBody += "</td>";
            _mailBody += "</tr>";

        }

        _mailBody += "</table>";
        _mailBody += "<br/><br/>";
        _mailBody += "<u>" + Resources.Proposal.ForBankIn + "</u>";
        _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg1;
        _mailBody += "<br/>" + Resources.Proposal.LineQrScan;
        _mailBody += "<br/><div style=\"text-align:center; width:400px\">";
        _mailBody += "<img runat=\"server\" id=\"imgSpecial\" alt=\"Line QR\" src=\"" + _currentDomainUrl + "/images/callme/line_qr.jpg\" /></div>";


        _mailBody += "<br/>";

        _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg2;

        _mailBody += "<br/>";

        _mailBody += "<br/><strong>" + Resources.Proposal.Remarks + "</strong>";
        //[Yui] @13/09/2013
        if (!IsGGSpecial)
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsg1;
        }
        else
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsgGGSpecial;
        }
        _mailBody += "<br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.CompareXpress + "</strong>";
        _mailBody += "<br/>" + Resources.Proposal.CompareXpressAddress;

        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";

        _mailBody += "<hr />";
        _mailBody += Resources.EmailMessage.Footer;
        _mailBody += "<br/>";
        _mailBody += "<br /><i>" + Resources.EmailMessage.NoReply + "</i>";
        _mailBody += "<hr />";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    private bool SendProposalToAgent(string CITempResultId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";
        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }
            
            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;
            

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {
                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_TO"].ToString();
        string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_CC"].ToString();
        string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_BCC"].ToString();
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "<Online> - " + Resources.Proposal.PendingPayment + " - " + Resources.EmailMessage.BKISubject;
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentName] != null)
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + " - " + Session[CE.Global.General.AgentName].ToString() + "</strong><br /><br />";
        }
        else
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + "</strong><br /><br />";
        }
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _refNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
        _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>"+ Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        _mailBody += "</table> <br /><br />";

        //Sakthi on 18 Jan 2012 -- Start
        DataSet _dsResults = new DataSet();
        DataView dvResults = new DataView();
        SortedList _sPara = new SortedList();

        _sPara.Add("@CarId", Convert.ToInt64(Session[General.CarId].ToString()));
        _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
        _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
        if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
        {
            dvResults = _dsResults.Tables[0].DefaultView;
            dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
        }
        //Sakthi on 18 Jan 2012 -- End

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

        DataTable dtResults = dvResults.ToTable();
        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            //logo
            string logourl = "";
            string insurername = dtResults.Rows[0]["PackageName"].ToString();
            if (dtResults.Rows[0]["PackageName"].ToString() != "GluayGluay.com Special")
            {
                logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);
            }
            else
            {
                logourl = "/images/public/gluaygluay_logo.png";
                insurername += " (" + Resources.CarInsuranceResultPage.SpecialNCB + ")";
            }

            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";

            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";

            float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
            string monthlyInstallment = "";

            if (_fMonthlyPremiumAmount > 0.0f)
            {
                string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
                monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
            }
            else
            {
                monthlyInstallment = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }

            //Deductible  
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.DEC + "</strong></td>";
            float _fDEC = Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
            string deductible = "";
            if (_fDEC > 0.0f)
            {
                deductible = String.Format("{0:0,0.00}", _fDEC);
            }
            else
            {
                deductible = Resources.CarInsuranceResultPage.Waived;  //"<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + deductible + "</td>";
            _mailBody += "</tr>";

            string suminsured = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString()));
            if (suminsured == "0")
            {
                suminsured = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            //Own Damage
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.OwnDamage + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + suminsured + "</td>";
            _mailBody += "</tr>";

            //Fire
            string fire = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString()));
            if (fire == "0")
            {
                fire = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Fire + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + fire + "</td>";
            _mailBody += "</tr>";

            //Theft
            string theft = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString()));
            if (theft == "0")
            {
                theft = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Theft + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + theft + "</td>";
            _mailBody += "</tr>";

            //TPPD
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.TPPD + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIA
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIA + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIP
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIP + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //PA Driver
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.PADriver + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</td>";
            _mailBody += "</tr>";

            int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
            string medicalExpense = "";

            if (_MedicalExpense == 0)
            {
                medicalExpense = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
            }
            else
            {
                medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
            }

            //Medical Expense
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.MED + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + medicalExpense + "</td>";
            _mailBody += "</tr>";

            //BB
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.BailBond + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //CTPL
            if (_isCTPL == "Yes")
            {
                //premium before ctpl
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.AnnualPremium + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

                double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);

                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

                //ctplamount
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.CTPL + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5;'>";

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

            }


            //premium
            _mailBody += "<tr>";
            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

            if (_isCTPL == "No")
            {
                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
            }
            else
            {
                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</strong>";
            }
            _mailBody += "</td>";
            _mailBody += "</tr>";
        }

        _mailBody += "</table>";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessageToAgent(_emailTo, _emailCC, _emailBCC, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    protected void rdoMailingAddress_CheckedChanged(object sender, EventArgs e)
    {
        if (rdoMailingAddressYes.Checked)
        {
            rdoMailingAddressNo.Checked = false;
            pnlMailingAddress.Visible = false;

            rfvMailingAddress.Enabled = false;
            rfvMailingSubDistrict.Enabled = false;
            rfvMailingDistrict.Enabled = false;
            rfvMailingProvince.Enabled = false;
            rfvMailingPostalCode.Enabled = false;
            revMailingPostalCode.Enabled = false;

            txtMailingAddress.Text = "";
            txtMailingSubDistrict.Text = "";
            txtMailingDistrict.Text = "";
            txtMailingProvince.Text = "";
            txtMailingPostalCode.Text = "";
        }
        else if (rdoMailingAddressNo.Checked)
        {
            rdoMailingAddressYes.Checked = false;
            pnlMailingAddress.Visible = true;

            rfvMailingAddress.Enabled = true;
            rfvMailingSubDistrict.Enabled = true;
            rfvMailingDistrict.Enabled = true;
            rfvMailingProvince.Enabled = true;
            rfvMailingPostalCode.Enabled = true;
            revMailingPostalCode.Enabled = true;
        }
    }

    //[Yui] @13/09/2013
    private void SaveConfirmDisclaimer(int ProviderId, long CECarMoreDetailId)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCarMoreDetailUpdateSingleItemDisclaimer]";
            SortedList _spList = new SortedList();
            _spList.Add("@ProviderId", ProviderId);
            _spList.Add("@CECarMoreDetailId", CECarMoreDetailId);
            Int64 _retValue = _db.ExecuteSP(_spName, _spList);
            //return _retValue == 1;
        }
        catch (Exception)
        {

            throw;
        }
    }

}
